package com.www.applyword.adapter;

import android.content.Context;
import android.os.Handler;
import android.widget.EditText;

import androidx.recyclerview.widget.DefaultItemAnimator;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.classic.adapter.BaseAdapterHelper;
import com.classic.adapter.CommonRecyclerAdapter;
import com.www.applyword.R;
import com.www.applyword.bean.DynaminDetailsBean;
import com.www.applyword.ui.chat.DynamicDetailsActivity;
import com.www.applyword.utils.ImageUtil;

/**
 * author : huang
 * date   : 2019/10/21 0021 15:06
 * version: 1.0
 * @author Administrator
 */
public class DynamicAdapter2 extends CommonRecyclerAdapter<DynaminDetailsBean.ForumCommentBeanX> {
    public DynamicDetailsActivity context;
    private String forumID;
    private EditText etSendComment;
    public String forumComment_parentID;
    private RecyclerView view;


    public DynamicAdapter2(Context context, String forumID, EditText etSendComment) {
        super(context, R.layout.item_list_dynamic2);
        this.context = (DynamicDetailsActivity) context;
        this.forumID = forumID;
        this.etSendComment = etSendComment;
    }


    @Override
    public void onUpdate(BaseAdapterHelper helper, DynaminDetailsBean.ForumCommentBeanX item, int position) {
        ImageUtil.setImage(helper.getView(R.id.civ_personal_head_image), (String) item.getForumComment().getForumComment_UserImg());
        helper.setText(R.id.tv_name, (String) item.getForumComment().getForumComment_UserName());
        helper.setText(R.id.tv_time, (String) item.getForumComment().getForumComment_CreateTime());
        helper.setText(R.id.tv_dynamic_detail, (String) item.getForumComment().getForumComment_Content());
        view = helper.getView(R.id.rv_new_comment);
        view.setLayoutManager(new LinearLayoutManager(context));
        view.setItemAnimator(new DefaultItemAnimator());
        DynamicReplyAdapter   mDynamicAdapter = new DynamicReplyAdapter(context);
        view.setAdapter(mDynamicAdapter);
        mDynamicAdapter.replaceAll(item.getForumCommentItemList(), true);

        helper.getView(R.id.sb_reply).setOnClickListener(v -> {
            Handler handle = new Handler();
            handle.postDelayed(() -> {
                if (null != context) {
                    DynamicDetailsActivity.inputMethodManager.showSoftInput(etSendComment, 0);
                    etSendComment.setHint("回复" + item.getForumComment().getForumComment_UserName());
                    forumComment_parentID = item.getForumComment().getForumComment_ID();
                }
            }, 0);
        });
    }
}

